/**
 * \* Created with IntelliJ IDEA.
 * \* User: 冯若航
 * \* Date: 2021/4/30
 * \* Time: 13:11
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class 删除链表节点 {
    public class ListNode{
        int val;
        ListNode next;
        ListNode(int x){
            val=x;
        }
    }
    public ListNode deleteNode(ListNode head, int val){
        if(head.val==val){
            return head.next;
        }

        ListNode pre=head,cur=head.next;
        while(cur!=null&&cur.val!=val){
            pre=cur;
            cur=cur.next;
        }
        if(cur!=null) {
            pre.next=cur.next;
        }
        return head;
    }
}